package com.wxapp.admin.service.controller.client;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.wxapp.admin.api.pojo.vo.login.QLoginVo;
import com.wxapp.admin.service.service.LoginService;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.common.core.filter.except.ThrowMyException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author lgl
 * @Description
 * @Datetime 2023/10/17 14:25
 * @Modified By
 */
@RequestMapping("/client/")
@Tag(name = "登录")
@RequiredArgsConstructor
@RestController
public class LoginClientController extends IBaseController {
    private final LoginService loginService;
    /**
     * 微信登录对前端开放
     */
    @PostMapping("/login")
    @SentinelResource(value = "login")
    @Operation(summary = "登录接口")
    public ResultVm<String> login(@Validated @RequestBody QLoginVo qLoginVo) throws ThrowMyException {
        return loginService.login(qLoginVo, getRequest());
    }
    /**
     * 推出登录
     */
    @PutMapping("logOff")
    @Operation(summary = "退出登录")
    public ResultVm<String> logOff(@Schema(hidden = true) @User UserVo userVo){
        return loginService.logOff(userVo);
    }
}
